package com.xg.serviceOrder.controller;

import com.alibaba.fastjson.JSON;
import com.xg.common.result.ApiResult;
import com.xg.serviceOrder.entity.UsedCarOrder;
import com.xg.serviceOrder.entity.UsedCarOrderItem;
import com.xg.serviceOrder.service.UsedCarOrderItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@RequestMapping("/orderItem")
@Controller
public class OrderItemController {

    @Autowired
    private UsedCarOrderItemService orderItemService;

    /**
     * 已下单,订单明细添加,跳转用户支付
     * @return
     */
    @GetMapping("/add")
    public String index(@RequestParam("orderId") Long orderId,@RequestParam("orderNumber") String orderNumber, Model model){
        ApiResult result = orderItemService.add(orderId,orderNumber);
        if (result.getCode() != 1){
            // error
            return "error";
        }
        UsedCarOrderItem usedCarOrderItem = JSON.parseObject(JSON.toJSONString(result.getData()), UsedCarOrderItem.class);
        model.addAttribute("orderItem",usedCarOrderItem);
        return "pay";
    }

}
